package com.example.demo.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;


/**
 * 角色
 * @author
 * @date
 */
@Entity
@Getter
@Setter
@Table(name = "t_role")
@org.hibernate.annotations.Table(appliesTo = "t_role",comment="角色表")
public class Role implements Serializable {
    /** serialVersionUID*/
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = {Update.class})
    private Long id;

    @NotBlank
    @Column(name = "role_name")
    private String roleName;

    @Column(name = "level")
    private Integer level = 3;

    @NotBlank
    @Column(name = "data_scope")
    private String dataScope = "本级";

    @Column(name = "create_id")
    private Long createId;

    @Column(name = "create_time")
    @CreationTimestamp
    private Timestamp createTime;

    @Column(name = "update_id")
    private Long updateId;

    @Column(name = "update_time")
    @CreationTimestamp
    private Timestamp updateTime;

    @Column
    private String remark;

    /** 是否删除*/
    @Column(name = "isdel")
    private Boolean isdel;

    @ManyToMany
    @JoinTable(name = "t_roles_menus", joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "menu_id",referencedColumnName = "id")})
    private Set<Menu> menus;

    public @interface Update {}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Role role = (Role) o;
        return Objects.equals(id, role.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
